<?php
if (isset($_POST['sid']) && isset($_POST['op'])){
include '../c/config.php';
$url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appId.'&secret='.$secret;
include '../jssdk.php';
$jssdk = new JSSDK($appId, $secret);
$access_token = $jssdk->getAccessTokenNew();
$media_id=$_POST['sid'];
$url='https://api.weixin.qq.com/cgi-bin/media/get?access_token='.$access_token.'&media_id='.$media_id;
$getData=file_get_contents($url);
$openid=$_POST['op'];
file_put_contents('/var/www/kelon/upload/'.$openid.'.jpg', $getData);

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
$mysqli->query("insert into umedia(openid,mid,createtime) values('".$openid."','".$media_id."','".date("Y-m-d H:i:s")."') ");
$mysqli->close();

echo json_encode(array('s'=>'ok','n'=>$openid.'.jpg?v='.rand(1,9999)));
}